/**
 * ****************************** ICE *******************************
 * ========================================================================
 * Project:  basicsipcall
 * Package: org.ice4apps.talk.callManager.Features 
 * File:  IceTalkFeature.java
 * Author: biju
 * Date: Feb 23, 2010
 * Description:
 * ========================================================================
 */
package org.ice4apps.talk.callManager;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.sip.SipApplicationSession;
import javax.servlet.sip.SipFactory;

import org.ice4apps.util.IceLog;
import org.ice4apps.talk.callManager.UserSession;
import org.ice4apps.talk.entity.UserSessionMessage;

/**
 * @author biju
 *
 */
public abstract class IceTalkFeature {
	protected static SipFactory sipFactory = null;
	protected SipApplicationSession session = null;
	
	public IceTalkFeature () throws ServletException {
		IceLog.info(this.getClass(), "IceTalkFeature");
		if (sipFactory == null) {
			IceLog.info(this.getClass(), "Creating sipFactory");
            try {                   
                    // Getting the Sip factory from the JNDI Context
                    // Properties jndiProps = new Properties();                        
                    Context initCtx = new InitialContext();
                    Context envCtx = (Context) initCtx.lookup("java:comp/env");
                    sipFactory = ((SipFactory) envCtx.lookup("sip/IceCall/SipFactory"));
            } catch (NamingException e) {
                    throw new ServletException("JNDI problem ", e);                       
            }
		}
		session = sipFactory.createApplicationSession();
			
	}

	public abstract void processMessage(UserSessionMessage msg);

}
